home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / passwrd9.zip / PWINT.ASM < prev    next >
Assembly Source File  |  1989-03-15  |  14KB  |  443 lines

  1. ;============================================================================
  2. ;        Title - PWINIT           DATE: 3/15/89
  3. ;        This program is used with PASSWORD.ASM
  4. ;        and its resulting file PASSWORD.BIN after
  5. ;        compiling with MASM and converting it
  6. ;        to a binary image file using EXE2BIN.EXE.
  7. ;
  8. ;        The resulting EXE file will take an uninitialized
  9. ;        PASSWORD.BIN file and insert the password of
  10. ;        your choice and then encode the resulting
  11. ;        PASSWORD.SYS file to transfer under whatever
  12. ;        name you desire (as long as the name in CONFIG.SYS
  13. ;        matches ie:DEVICE=PASSWORD.SYS) to your boot disk.
  14. ;        I would suggest using a different name to conceal
  15. ;        your intentions!
  16.  
  17. ;============================================================================
  18. Dos    equ    21h
  19. ;============================================================================
  20. code segment                    ; Define code segment
  21. ;============================================================================
  22.  
  23. main    proc    far
  24.  
  25.     assume    cs:code,ds:data,es:file
  26.  
  27. start:                        ; Main starting address
  28.  
  29. ; Set ds to our data segment
  30.  
  31.     mov    ax,data                ;Data segment address
  32.     mov    ds,ax                ;Move into ds register
  33.     mov    ax,file                ;Get File segment
  34.     mov    es,ax                ;Set es: to file segment
  35.     call    check_video            ;See what type of monitor
  36.     mov    dx,offset org_file_name        ;Point to Uninit file name
  37.     call    open_file            ;Open file for read only
  38.     mov    old_handle,ax            ;Store the handle
  39.     mov    bx,ax                ;Set up for read
  40.     mov    dx,offset ds:file_buffer    ;Point to file buffer area
  41.     mov    cx,800h                ;Set number of characters
  42.     push    bx                ;Save the file handle
  43.     call    read_file            ;Read file into buffer
  44.     mov    file_size,ax            ;Store number of bytes in file
  45.     pop    bx                ;Restore the file handle
  46.     call    close_file            ;Close the old file
  47.     call    clear_screen            ;Clear the CRT
  48.     call    input_word            ;Ask user for PASSWORD
  49.     call    box                ;Clear the entry box
  50.     call    off_screen            ;Get cursor out of box
  51.     mov    ax,word ptr ds:file_buffer+22    ;Get count of char to encode
  52.     mov    scramble_count,ax        ;Store it for later
  53.     mov    ax,offset es:file+24        ;Point to PASSWORD address
  54.     mov    pass_location,ax        ;Store the offset
  55.     mov    di,ax                ;Move offset to di
  56.     push    di                ;Save it for the moment
  57.     xor    cx,cx                ;Zero the counter
  58.     mov    cl,password+1            ;Get user entered char. count
  59.     inc    cl                ;Account for char. count
  60.     mov    ax,offset password+1        ;Point to user password
  61.     mov    si,ax                ;Move pointer into si
  62.     rep    movsb                ;Move the PASSWORD into the
  63.                         ;new file area
  64.     pop    di                ;Restore es:offset to new
  65.                         ;file password area
  66.     mov    cx,scramble_count        ;Load the char count to encode
  67.     push    ds                ;Save original data segment
  68.     push    es
  69.     pop    ds                ;Make ds=es
  70.     mov    si,di                ;Make di & si point to the
  71. scramble:                    ;same bytes
  72.     lodsb                    ;Get a byte
  73.     sub    al,40h                ;Remove 40h
  74.     stosb                    ;Store the byte
  75.     loop    scramble            ;Loop until done
  76.     pop    ds                ;Restore the original ds
  77.     mov    dx,offset new_file_name        ;Point to the new file name
  78.     call    create_file            ;Create it
  79.     mov    bx,ax                ;Get the file handle into bx
  80.     push    bx                ;Save it
  81.     mov    cx,file_size            ;Load the cx with the file
  82.                         ;size
  83.     mov    dx,offset ds:file_buffer    ;Point to the file buffer
  84.     call    write_file            ;Write the new file
  85.     pop    bx                ;Restore the file handle
  86.     call    close_file            ;Close the new file
  87.     mov    ah,8fh                ;Set attribute for display
  88.     mov    bx,offset msg_4            ;Point to the complete msg.
  89.     mov    cx,msg_4_len            ;Length of message
  90.     mov    dx,0d1ch            ;Location to write it
  91.     call    write_crt            ;Display message
  92.  
  93. done:
  94.     mov    ax,4c00h
  95.     int    dos                ;Return to DOS
  96.  
  97. main    endp        ;End of main program
  98.  
  99. ;============================================================================
  100.  
  101. check_video    proc    near            ;See where video RAM is
  102.  
  103.     mov    ah,0fh                ;via video ROM
  104.     int    10h                
  105.     cmp    al,07h                ;See if Mono card installed
  106.     jz    set_mono            ;Jump to monochrome routine
  107.  
  108.     mov    video_location,0b800h        ;If not mono then Color RAM
  109.     jmp    video_done            ;Exit routine
  110.  
  111. set_mono:
  112.  
  113.     mov    video_location,0b000h        ;Set location to Mono RAM
  114.  
  115. video_done:
  116.  
  117.     ret
  118.  
  119. check_video    endp
  120.  
  121. ;============================================================================
  122. ;The following routines are the direct CRT display code
  123. ;============================================================================
  124.  
  125. write_crt    proc    near
  126.  
  127.     push    es                ;Save original es
  128.     push    dx                ;Save location to write
  129.     push    ax                ;Save the attribute
  130.     push    cx                ;Save the character count
  131.     push    dx                ;Save for the moment
  132.     mov    cx,02h                ;Set the multiplier
  133.     mov    ax,video_location        ;Get the address of video RAM
  134.     mov    es,ax                ;Set the es register to RAM
  135.     mov    si,bx                ;Point si to the message
  136.     xor    ax,ax                ;Zero the ax
  137.     mov    al,dl                ;Move to al the column
  138.     sub    al,1                ;Adjust the al
  139.     imul    cx                ;Times to for actual column
  140.     pop    dx                ;Get the original location
  141.     mov    dl,al                ;Store column in dl
  142.     mov    al,dh                ;Move into ax the row
  143.     push    dx                ;Save for the moment
  144.     sub    ax,1                ;Adjust the ax
  145.     mov    cx,160                ;80 times 2 for actual offset
  146.     imul    cx
  147.     pop    dx                ;Get dx back
  148.     and    dh,00h                ;Zero the dh
  149.     add    ax,dx                ;Add the column offset to the
  150.     mov    di,ax                ;row and move di to the actual
  151.                         ;memory position
  152.     pop    cx                ;Restore character count
  153.     pop    ax                ;Restore the attribute
  154.  
  155. write_crt_1:
  156.  
  157.     lodsb                    ;Load a byte of message
  158.     stosw                    ;Store byte & attribute to RAM
  159.     loop    write_crt_1            ;Loop until cx=0
  160.     pop    dx                ;Restore original dx
  161.     pop    es                ;restore original es
  162.     ret                    ;And return
  163.  
  164. write_crt    endp
  165. ;============================================================================
  166.  
  167. write_cursor    proc    near
  168.  
  169. off_screen:
  170.  
  171.     xor    bx,bx                ;Zero bx (page 0) and set
  172.     xor    dx,dx                ;position to upper left corner
  173.                         
  174. position_cursor:
  175.  
  176.     mov    ah,02h                ;Have DOS reset the cursor 
  177.     int    10h                ;where we want it
  178.     ret                    ;And return
  179.  
  180. clear_screen:
  181.  
  182.     mov    ax,0600h            ;Use DOS scroll to clear CRT
  183.     mov    bh,07                ;Set attribute
  184.     xor    cx,cx                ;Upper left corner 0,0
  185.     mov    dx,184fh            ;Lower right 24,79
  186.     int    10h
  187.     ret                    ;And return
  188.  
  189. write_cursor    endp
  190.  
  191. ;============================================================================
  192. ;Area to get the user password
  193. ;============================================================================
  194.  
  195. input_word    proc    near
  196.  
  197.     call    box                ;Make input display box
  198.     mov    ah,0fh                ;Set attribute for display
  199.     mov    bx,offset msg_1            ;Point to opening mess.
  200.     mov    cx,msg_1_len            ;Set message length
  201.     mov    dx,0d19h            ;Location on CRT
  202.     call    write_crt            ;Display it
  203.     mov    dx,0c27h            ;Address for cursor
  204.     xor    bx,bx                ;Zero bx : Page 0
  205.     call    position_cursor            ;set cursor to entry position
  206.     mov    ax,0c0ah            ;Set up to use DOS buffer
  207.     mov    dx,offset password        ;input routine (point to
  208.                         ;our buffer
  209.     int    DOS                ;Get input string
  210.     call    box                ;Clear the box
  211.     mov    ah,0fh                ;Load attribute
  212.     mov    bx,offset msg_2            ;Point to next message
  213.     mov    cx,msg_2_len            ;Load the length
  214.     mov    dx,0c19h            ;Load where to display it
  215.     call    write_crt            ;Write the display
  216.     xor    cx,cx                ;Zero the count register
  217.     mov    cl,password+1            ;Load # of char entered
  218.     mov    bx,offset password+2        ;Point to the string
  219.     mov    dx,0c27h            ;Address to display
  220.     mov    ah,8fh                ;Load attribute
  221.     call    write_crt            ;Display entered password
  222.                         ;for conformation
  223.     mov    ah,0fh                ;Load attribute
  224.     mov    bx,offset msg_3            ;Point to confirm message
  225.     mov    cx,msg_3_len            ;Length
  226.     mov    dx,0e19h            ;Location for display
  227.     call    write_crt            ;Display message
  228.  
  229. char_loop:
  230.  
  231.     mov    dx,0d33h            ;Location for cursor
  232.     xor    bx,bx                ;Page 0
  233.     call    position_cursor            ;Position cursor for input
  234.                         ;of a Y or N answer
  235.     mov    ah,0ah                ;Write a blank at the cursor
  236.     mov    al,' '                ;to erase a answer that is
  237.     mov    cx,01h                ;not a Y or N
  238.     int    10h
  239.     mov    ah,01h                ;Get one character
  240.     int    DOS
  241.     and    al,5fh                ;Convert to upper case
  242.     cmp    al,'Y'                ;If PASSWORD confirmed then
  243.     je    ok                ;jump to a return
  244.     cmp    al,'N'                ;If not, then ask for new 
  245.     je    input_word            ;password
  246.     mov    ax,0e07h            ;If neither then ring bell
  247.     int    10h                ;and ask for Y or N
  248.     jmp    char_loop
  249.  
  250. ok:    ret                    ;PASSWORD ok.  Set up
  251.                         ;PASSWORD.SYS
  252. input_word    endp
  253. ;====================================